<?php
include('../../Redirect_modules.php');
DrawBC("School Setup >> ".ProgramTitle());

if((clean_param($_REQUEST['action'],PARAM_ALPHAMOD) == 'update') && (clean_param($_REQUEST['button'],PARAM_ALPHAMOD)=='Save') && clean_param($_REQUEST['values'],PARAM_NOTAGS) && $_POST['values'] && User('PROFILE')=='admin')
{

	$sql = 'UPDATE school_years SET ';
	foreach($_REQUEST['values'] as $column=>$value)
	{
		$value=paramlib_validation($column,$value);
		$sql .= $column.'=\''.str_replace("\'","''",$value).'\',';
	}
	$sql = substr($sql,0,-1) . ' WHERE SCHOOL_ID=\''.UserSchool().'\' AND SYEAR=\''.UserSyear().'\'';
	DBQuery($sql);
		
}
	
$sys_pref = DBGet(DBQuery('SELECT FEE_FULL_YEAR1, FEE_FULL_YEAR2, FEE_FULL_YEAR3, FEE_FULL_YEAR4, FEE_CREDIT FROM school_years WHERE SCHOOL_ID='.UserSchool().' AND SYEAR='.UserSyear()));
$sys_pref = $sys_pref[1];
$school_name = DBGet(DBQuery('SELECT TITLE FROM schools WHERE ID='.UserSchool().' LIMIT 1'));
PopTable('header', $school_name[1]['TITLE'].' fees in year '.UserSyear().'-'.(UserSyear() + 1));
if($sys_pref==''){
	echo "<FORM name=sys_pref id=sys_pref action=Modules.php?modname=$_REQUEST[modname]&action=insert&page_display=system_preference method=POST>";
}else{
	echo "<FORM name=sys_pref id=sys_pref action=Modules.php?modname=$_REQUEST[modname]&action=update&page_display=system_preference method=POST>";
}
echo "<table width=300px><tr><td><table border=0 cellpadding=4 align=center>";
echo "<tr><td><strong>Fees full year 1 (USD): </strong> </td><td>".TextInput($sys_pref['FEE_FULL_YEAR1'],'values[FEE_FULL_YEAR1]', '','class=cell_floating size=5')."</td></tr>";
echo "<tr><td><strong>Fees full year 2 (USD): </strong> </td><td>".TextInput($sys_pref['FEE_FULL_YEAR2'],'values[FEE_FULL_YEAR2]', '','class=cell_floating size=5')."</td></tr>";
echo "<tr><td><strong>Fees full year 3 (USD): </strong> </td><td>".TextInput($sys_pref['FEE_FULL_YEAR3'],'values[FEE_FULL_YEAR3]', '','class=cell_floating size=5')."</td></tr>";
echo "<tr><td><strong>Fees full year 4 (USD): </strong> </td><td>".TextInput($sys_pref['FEE_FULL_YEAR4'],'values[FEE_FULL_YEAR4]', '','class=cell_floating size=5')."</td></tr>";

echo "<tr><td><strong>A credit (USD) :</strong></td><td>".TextInput($sys_pref['FEE_CREDIT'],'values[FEE_CREDIT]', '','class=cell_floating size=5')."</td></tr>";
echo "</table></td></tr></table>";
DrawHeader('','',"<INPUT TYPE=SUBMIT name=button id=button class=btn_medium VALUE='Save'></CENTER>");
echo "</FORM>";
PopTable('footer');

function _makeContentInput($value,$name)
{	global $THIS_RET;

	if($THIS_RET['ID'])
		$id = $THIS_RET['ID'];
	else
		$id = 'new';
		$THIS_RET['ID'];
	return TextareaInput($value,"values[$id][$name]",'','rows=8 cols=55');
}
function makeTextInput($value,$name)
{	global $THIS_RET;
	if($THIS_RET['ID'])
		$id = $THIS_RET['ID'];
	else
		$id = 'new';
	
	if($name!='MESSAGE')
		$extra = 'size=5 maxlength=2 class=cell_floating';
		else 
	$extra = 'class=cell_floating ';
	
	if($name=='SORT_ORDER')
		$comment = '<!-- '.$value.' -->';

	return $comment.TextInput($value,'values['.$id.']['.$name.']','',$extra);
}
function _makeRadio($value,$name)
{	global $THIS_RET;
	if($THIS_RET['ID'])
		$id = $THIS_RET['ID'];
	else
		$id = 'new';
	
	if($THIS_RET[$name]=='Y')
		return "<TABLE align=center><TR><TD><INPUT type=radio name=val[".$name."] value=".$id.",".$name." CHECKED></TD></TR></TABLE>";
	else
		return "<TABLE align=center><TR><TD><INPUT type=radio name=val[".$name."] value=".$id.",".$name."".(AllowEdit()?'':' ')."></TD></TR></TABLE>";
}

?>